# -*- coding: UTF-8 -*-
from django.db import models

# Create your models here.
class UserInfo(models.Model):
    USERTYPE = (
        (u"积极分子", u"积极分子"),
        (u"预备党员", u"预备党员"),
        (u"正式党员", u"正式党员"),
        (u"支部管理员", u"支部管理员"),
        (u"党建辅导员", u"党建辅导员"),
    )
    GENDER = (
        (u'male', u"male"),
        (u'female', u"female"),
    )
    phone = models.CharField(
        max_length=20,
        verbose_name=u'手机号',
        default="",
    )
    nickname = models.CharField(
        max_length=50,
        verbose_name=u'昵称',
        default=u'',
    )
    name = models.CharField(
        max_length=50,
        verbose_name=u'真实姓名',
        default=u'',
    )
    gender = models.CharField(
        choices=GENDER,
        max_length=20,
        default=u'male',
        verbose_name=u"性别",
    )
    stuNum = models.CharField(
        verbose_name=u"学号",
        default=u'',
        max_length=20,
    )
    classNum = models.CharField(
        verbose_name=u"班级",
        default=u'',
        max_length=20,
    )
    unionid = models.CharField(
        max_length=50,
        verbose_name=u'微信unionid',
        default=u'',
    )
    openid = models.CharField(
        max_length=50,
        verbose_name=u'微信openid',
        default=u'',
    )
    access_token = models.CharField(
        max_length=256,
        verbose_name=u'token',
        default=u'',
    )
    refresh_token = models.CharField(
        max_length=256,
        verbose_name=u'refresh_token',
        default=u'',
    )
    headimgurl = models.URLField(
        verbose_name=u'用户头像地址',
        default=u''
    )
    userType = models.CharField(
        choices=USERTYPE,
        max_length=20,
        default=u'',
        verbose_name=u"用户类型",
    )
    isGraduated = models.BooleanField(
        verbose_name=u'是否毕业',
        default=False,
    )
    createTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"创建时间",
    )

    def __unicode__(self):
        return self.name
    def __str__(self):
        return self.name
    class Meta:
        ordering = ('createTime',)
        verbose_name = '用户信息'  # 单数形式
        verbose_name_plural = '用户信息'  # 复数形式


# 阿里云       
class Ali(models.Model):
    region = models.CharField(
        max_length=256,
        verbose_name=u'地区',
        default=u'',
    )
    accessKeyId = models.CharField(
        max_length=256,
        verbose_name=u'id',
        default=u'',
    )
    accessKeySecret = models.CharField(
        max_length=256,
        verbose_name=u'secret',
        default=u'',
    )
    bucket = models.CharField(
        max_length=256,
        verbose_name=u'bucket',
        default=u'',
    )



class VSession(models.Model):
    CLIENTTYPE = (
        (0, u"小程序"),
        (1, u"浏览器"),
        (2, u"管理后台"),
    )
    token = models.CharField(
        max_length=20,
        verbose_name=u'临时秘钥',
        db_index=True, #建立索引加快查找
    )
    userInfo = models.ForeignKey(
        UserInfo,
        verbose_name=u"用户信息",
        on_delete=models.CASCADE,
    )
    clientType = models.SmallIntegerField(
        choices=CLIENTTYPE,
        default=1,
        verbose_name=u"客户端类型",
    )
    lastVisiteTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"最晚访问时间",
    )
    isActive = models.BooleanField(
        verbose_name=u'是否活跃',
        default=True,
    )
    createTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"创建时间",
    )
    
    def __unicode__(self):
        return self.userInfo

    class Meta:
        ordering = ('createTime',)


class InviteCode(models.Model):
    """
    邀请码表
    """
    inviteCode = models.CharField(
        max_length=256,
        verbose_name=u'邀请码'
    )
    createTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"创建时间",
    )
    isUsed = models.BooleanField(
        verbose_name=u'是否使用过',
        default=False,
    )
    def __str__(self):
        return self.inviteCode
    class Meta:
        verbose_name = '邀请码'  # 单数形式
        verbose_name_plural = '邀请码'  # 复数形式

class AccountInfo(models.Model):
    """
    账户密码
    """
    username = models.CharField(
        max_length=50,
        verbose_name=u'登录账号',
        default=u'',
    )
    userpwd = models.CharField(
        max_length=50,
        verbose_name=u'登录密码',
        default=u'',
    )
    userInfo = models.OneToOneField(
        UserInfo,
        verbose_name=u"用户信息",
        on_delete=models.CASCADE,
    )